package com.example.androidclass;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class CampusNetwork extends AppCompatActivity {

    private EditText editId;
    private EditText editPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.campus_activity);
        editId = findViewById(R.id.edit_id);
        editPassword = findViewById(R.id.edit_password);
        Button saveData = (Button) findViewById(R.id.save);
        Button restoreData = (Button) findViewById(R.id.restore_id);

        saveData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences.Editor editor = getSharedPreferences("campusNetwork", MODE_PRIVATE).edit();
                editor.putString("id", String.valueOf(editId.getText()));
                editor.putString("password", String.valueOf(editPassword.getText()));
                editor.apply();
            }
        });

        restoreData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences preferences = getSharedPreferences("campusNetwork", MODE_PRIVATE);
                String id = preferences.getString("id", "");
                String password = preferences.getString("password", "");
                Log.d("Click", id);
                Log.d("Click", password);
            }
        });

    }


}






























